package chapter7;

import java.util.ArrayList;

public class ArrayListCollection {

	public static void main(String[] args) {

		ArrayList<String> items = new ArrayList<String>();
		
		items.add("red");
		items.add(0, "yellow");
		
		System.out.print("Display list contents with counter-controlled loop: ");

		for (int i = 0; i < items.size(); i++) {
			System.out.printf(" %s", items.get(i));
		}
		
		display(items, "\nDisplay list contents with enhanced for statement: ");
		
		items.add("green");
		items.add("yellow");
		display(items, "\nLista com dois novos elementos: ");
		
		items.remove("yellow");
		display(items, "\nRemove first instance of yellow: ");
		
		items.remove(1);
		display(items, "\nRemove o segundo elemento da lista (green): ");
		
		System.out.printf("\"red\" is %sin the list\n", items.contains("red") ? "": "not ");
		
		System.out.printf("Tamanho: %d", items.size());		
	}

	public static void display(ArrayList<String> items, String header) {
		System.out.print(header);
		
		for (String item : items) {
			System.out.printf("%d", item);
		}
		System.out.println();
	}	
	
}
